/**
 * Created by pankaj on 25/10/14.
 */
define(['jquery', 'module/form/validate'], function($, validateEmail){

    var form = function(){
        var validate = function(){
            var signUp = {};
            signUp.name = $("#signupform #fullName").val();
            signUp.userName = $("#signupform #userName").val();
            signUp.password = $("#signupform #password").val();
            signUp.cpassword = $("#signupform #cpassword").val();
            signUp.success = true;
            if (signUp.name.length == 0) {
                $("#signupform #fullNameError").css('display', 'block');
                signUp.success = false;
            } else {
                $("#signupform #fullNameError").css('display', 'none');
            }

            if (!validateEmail.validateEmail(signUp.userName)) {
                $("#signupform #userNameError").css('display', 'block');
                signUp.success = false;
            } else {
                $("#signupform #userNameError").css('display', 'none');
            }

            if (signUp.password.length == 0) {
                $("#signupform #passwordError").css('display', 'block');
                signUp.success = false;
            } else {
                $("#signupform #passwordError").css('display', 'none');
            }

            if (signUp.password != signUp.cpassword && !signUp.error) {
                $("#signupform #cpasswordError")
                    .css('display', 'block');
                signUp.success = false;
            } else {
                $("#signupform #cpasswordError").css('display', 'none');
            }
            return signUp.success;
        };
        // bind click event.

        // bind click event.
        $("#signupform #btn-login").click(function(event){
            if (validate()) {
                // submit the form.
                $("#signupform").submit();
            }
            event.preventDefault();
        });
    };
    return form;
});